

	/*******************************************************************************
*   			Impacts of a Large-Scale Parenting Program: 				   *
*					Experimental Evidence from Chile						   *
********************************************************************************


	REQUIRES:	"${dt_final}baseline_for figures.dta"
	CREATES:	${out_tables}/T2A_basebalance_malb.xls
				
	WRITEN BY:  Italo Lopez  [italolop@usc.edu]

********************************************************************************
	Prepare data
*******************************************************************************/

	* Load data
	use "$dt_int/baseline_for figures.dta", clear


	* Establish macros for regressions



/*******************************************************************************
Table A2: Baseline Balance: Child Maladaptive Behavior
*******************************************************************************/
	* Rename relevant variables
	*---------------------------------

	
	gen Evalplsivtot3=. 
    replace Evalplsivtot3=1 if t_per<=2 & t_per!=.
    replace Evalplsivtot3=2 if inrange(t_per,3,15) & t_per!=.
	replace Evalplsivtot3=3 if t_per>=16 & t_per!=.
	gen Evalplsivaud3=. 
    replace Evalplsivaud3=1 if  percentil_aud<=2 & t_per!=.
    replace Evalplsivaud3=2 if inrange( percentil_aud,3,15) & t_per!=.
	replace Evalplsivaud3=3 if  percentil_aud>=16 & t_per!=.
	gen Evalplsivexp3=. 
    replace Evalplsivexp3=1 if  percentil_e<=2 & t_per!=.
    replace Evalplsivexp3=2 if inrange( percentil_e,3,15) & t_per!=.
	replace Evalplsivexp3=3 if  percentil_e>=16 & t_per!=.
	tabulate Evalplsivtot3, g(plst)
	tabulate Evalplsivaud3, g(plsa)
	tabulate Evalplsivexp3, g(plse)
	g t_score_rec=ss_audi_PLSIV if t_per!=.
	g t_score_exp=ss_expre_PLSIV if t_per!=.

	* CBCL
	tabstat  ach_ttot, by(TIPO) s(mean sd)
	tabstat  ach_tint, by(TIPO) s(mean sd)
	tabstat  ach_text, by(TIPO) s(mean sd)

	tabulate ach_tot_3lev, g(acht)
	tabulate ach_int_3lev, g(achi)
	tabulate ach_ext_3lev, g(ache)

	*DCCS
	forvalues i=3/6 {

	g DCCSPunt`i'=DCCSPunt_old if  edadtramos==`i'
	g DCCS_pass`i'=DCCS_pass_old if  edadtramos==`i'
	tabulate DCCS_pass`i', g(dccs`i')

	}




iebaltab ach_ttot ach_tint ach_text acht*, grpvar(TIPO) save("${out_tables}/appendix/T2A_basebalance_malb.xlsx") ftest fmissok pttest pftest total replace



import excel using "${out_tables}/appendix/T2A_basebalance_malb.xlsx", clear
gen row = _n 
replace A = "T score, Global" if row == 4
replace A = "T score, Internalization" if row == 6 
replace A = "T score, Externalization" if row == 8 

replace A = "Clinical range (%)" if row == 10
replace A = "Risk (%)" if row == 12
replace A = "Normal (%)" if row == 14 
	
drop row


drop L 
export  excel using "${out_tables}/appendix/T2A_basebalance_malb.xlsx", replace

